/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package it.bbSimulator.Model.Panels;

import static it.bbSimulator.Model.Panels.PanelColor.Black;
import static it.bbSimulator.Model.Panels.PanelColor.Blue;
import static it.bbSimulator.Model.Panels.PanelColor.Green;
import static it.bbSimulator.Model.Panels.PanelColor.Prestige;
import static it.bbSimulator.Model.Panels.PanelColor.Purple;
import static it.bbSimulator.Model.Panels.PanelColor.Red;
import static it.bbSimulator.Model.Panels.PanelColor.Yellow;
import static it.bbSimulator.Model.Panels.PanelState.UNQUALIFIED;
import it.bbSimulator.Model.RepurchaseType;
import java.util.Date;

/**
 *
 * @author drforno
 */
public class Panel {

    int tHits;
    double target;
    double value;
    Date lockDate;
    Date qualifyDate;
    Date deadlineDate;
    RepurchaseType repSetting;
    PanelType pType;
    PanelState pState;
    PanelColor pColor;
    Date purchaseDate;

    public Panel(PanelColor c, PanelType t) {
        initPanel(c, t, 0, new Date());
    }

    /**
     *
     * @param c Panel's color
     * @param t Panel's type (purchased, repurchased,...)
     * @param value initial value
     * @param pDate purchase date
     */
    public Panel(PanelColor c, PanelType t, double value, Date pDate) {
        initPanel(c, t, value, pDate);
    }

    public PanelState getPanelState() {
        return pState;
    }

    public void setpState(PanelState pState) {
        this.pState = pState;
    }

    public PanelColor getPanelColor() {
        return pColor;
    }

    public PanelType getPanelType() {
        return pType;
    }

    public int gettHits() {
        return tHits;
    }

    public void settHits(int tHits) {
        this.tHits = tHits;
    }

    public double getTarget() {
        return target;
    }

    public void setTarget(double target) {
        this.target = target;
    }

    private void initPanel(PanelColor c, PanelType t, double value, Date purchaseDate) {
        pState = PanelState.UNQUALIFIED;
        pColor = c;
        switch (c) {
            case Yellow:
                target = 20;
                tHits = 5000;
                break;
            case Purple:
                target = 20;
                tHits = 5000;
                break;
            case Blue:
                target = 20;
                tHits = 5000;
                break;
            case Green:
                target = 20;
                tHits = 5000;
                break;
            case Red:
                target = 20;
                tHits = 5000;
                break;
            case Black:
                target = 20;
                tHits = 5000;
                break;
            case Prestige:
                target = 20;
                tHits = 5000;
                break;
        }
        pType = t;
        this.value = value;
        this.purchaseDate = purchaseDate;
    }

    public void Qualify() {
        pState = PanelState.QUALIFIED;
        this.Qualify(new Date());

    }

    public void Qualify(Date qDate) {
        pState = PanelState.QUALIFIED;
        qualifyDate = qDate;
    }

    public void Lock() {
        pState = PanelState.LOCKED;
        this.Lock(new Date());
    }

    public void Lock(Date lDate) {
        pState = PanelState.LOCKED;
        lockDate = lDate;
    }

    public void setValue(double val) {
        value = val;
    }

    public double getValue() {
        return value;
    }

    public void setRepurchase(RepurchaseType t) {
        this.repSetting = t;
    }

    public RepurchaseType getRepurchase() {
        return this.repSetting;
    }

    public Date getDeadlineDate() {
        return this.deadlineDate;
    }

    public Date getPurchaseDate() {
        return this.purchaseDate;
    }

    public Date getLockDate() {
        return this.lockDate;
    }

    public Date getQualifyDate() {
        return this.qualifyDate;
    }

    public void setDeadline(Date d) {
        this.deadlineDate = d;
    }

    public PanelState getState(Date refDate) {
        if ((getQualifyDate() != null && getQualifyDate().compareTo(refDate) < 0) && (getDeadlineDate() == null || getDeadlineDate().compareTo(refDate) > 0)) {
            return PanelState.QUALIFIED;
        }
        if ((getPurchaseDate() != null && getPurchaseDate().compareTo(refDate) < 0) && (getQualifyDate() == null || getQualifyDate().compareTo(refDate) > 0) && (getLockDate() == null || getLockDate().compareTo(refDate) > 0)) {
            return PanelState.UNQUALIFIED;
        }
        if ((getPurchaseDate() != null && getPurchaseDate().compareTo(refDate) < 0) && (getQualifyDate() == null || getQualifyDate().compareTo(refDate) > 0) && (getLockDate() != null && getLockDate().compareTo(refDate) < 0)) {
            return PanelState.LOCKED;
        }
        if (getDeadlineDate().compareTo(refDate) < 0) {
            return PanelState.FINISHED;
        }
        return null;
    }
}
